package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Zhou ShiYang
 * @Description:
 **/
@RestController
public class UserController {
    @Autowired
    private UserService userServiceImpl;

    /**
     * 查询
     * GetMapping 不支持@RequestBody
     * @return
     */
    @GetMapping("/user")
    public List<User> user(@RequestParam(value = "mobile",required = false) String mobile){
        User user = new User();
        if (!StringUtils.isEmpty(mobile)) {
            user.setMobile(mobile);
        }
        return userServiceImpl.find(user);
    }

    /**
     * 增加用户信息
     * @param user
     * @return
     */
    @PostMapping("/user")
    public int add(@RequestBody User user){
        return userServiceImpl.add(user);
    }


    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @PutMapping("/user")
    public int update(@RequestBody User user){
        return userServiceImpl.update(user);
    }

    /**
     * 删除用户信息
     * 逻辑删除
     * @param userId 预约信息 userId
     * @return
     */
    @DeleteMapping("/user/{userId}")
    public int delete(@PathVariable Integer userId){
        return userServiceImpl.delete(userId);
    }
}
